package com.sw.dubbo.web;

import com.sw.dubbo.api.MonitorService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Configuration
@EnableDubbo
@PropertySource("classpath:/dubbo-consumer.properties")
@SpringBootApplication
public class ConsumerApplication implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class);
    }
    @Reference
    MonitorService monitorService;
    @Override
    public void run(String... args) throws Exception {
        BlockingQueue blockingQueue=new ArrayBlockingQueue(10);

        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, blockingQueue);

        while (true) {
            threadPoolExecutor.execute(() -> {
                monitorService.methodA();
            });
            threadPoolExecutor.execute(() -> {
                monitorService.methodB();
            });
            threadPoolExecutor.execute(() -> {
                monitorService.methodC();
            });
            Thread.sleep(10);
        }


    }

}
